package com.wwy.arithmetic.newsuanfa;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 王伟羽
 * @program: arithmetictest
 * @description:
 * @create: 2025/03/31
 */

public class liangshuzhihe {
    //nums = [2,7,11,15], target = 9
    public int[] twoSum(int[] nums, int target) {
        Map<Integer,Integer> map = new HashMap<Integer,Integer>();
        int[] resp = new int[2];
        for(int i = 0 ;i<nums.length;i++){
            int num = target-nums[i];
            if(map.containsKey(num)){
                resp[0] = i;
                resp[1] = map.get(num);
            }
            map.put(nums[i],i);
        }
        return resp;
    }
}
